package com.example.controller;

import com.example.DTO.ShoppingCartDTO;
import com.example.result.Result;
import com.example.entity.Collect;
import com.example.service.ShoppingCartService;
import com.example.vo.ShoppingCartVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/ShoppingCart")
@Tag(name = "购物车", description = "购物车模块的描述")
public class ShoppingCartController {

    @Autowired
    private ShoppingCartService shoppingCartService;

    /**
     * 用户添加商品到购物车，如果已经存在则在原有的数据上 数量+amount
     * @param shoppingCartDTO
     * @return
     */
    @PostMapping("/addShoppingCart")
    @Operation(summary = "添加商品进入购物车")
    public Result addShoppingCart(@RequestBody ShoppingCartDTO shoppingCartDTO) {
       shoppingCartService.addShoppingCart(shoppingCartDTO);
       return Result.success();
    }

    /**
     * 查看用户的购物车
     * @param buyerId
     * @return
     */
    @GetMapping("/selectShCartById/{buyerId}")
    @Operation(summary = "查看用户的购物车")
    public Result selectShCartById(@PathVariable Integer buyerId) {
        return shoppingCartService.selectShCartById(buyerId);
    }

    /**
     * 批量删除用户购物车中的商品
     * @param ids
     * @return
     */
    @DeleteMapping("/delShoppingCartBatch")
    @Operation(summary = "批量删除用户购物车中的商品")
    public Result delShoppingCartBatch(@RequestBody List<Integer> ids){
        shoppingCartService.delShoppingCartBatch(ids);
        return Result.success();
    }
}
